<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition template="./../Template/AdminTemplate.xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"                        
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="content">
        <h:outputText value="#{userControl.setfield()}" />

        <h:form enctype="multipart/form-data">
            <p:panel id="panel" header="Register">

                <h:panelGrid columns="2">

                    <h:outputLabel value="UserName:" for="userName" />
                    <p:inputText id="userName" value="#{userControl.newUser.userName}" label="UserName">
                        <f:validateLength minimum="1"/>
                        <p:message id="msu" for="userName" display="UserName is not be empty "/>
                    </p:inputText>

                    <h:outputLabel value="Password:" for="password1" />
                    <p:password id="password1" value="#{userControl.newUser.passWord}" match="password2" label="Password" required="true">
                        <f:validateLength minimum="6"/>
                        <p:message id="msp1" for="password1" display="Password is not be empty "/>
                    </p:password>
                    
                    <h:outputLabel value="Confirm Password:" for="password2" />
                    <p:password id="password2" value="#{userControl.newUser.passWord}" label="Password2" required="true">
                        <p:message id="msp2" for="password2" display="Confirm Password should match with Password"/>
                    </p:password>

                    <h:outputLabel value="Sex:" for="sex" />
                    <p:selectOneRadio id="options" value="#{userControl.newUser.sex}" required="true" requiredMessage="Choose your gender">  
                        <f:selectItem itemLabel="Male" itemValue="true" />  
                        <f:selectItem itemLabel="Female" itemValue="false" />    
                    </p:selectOneRadio>

                    <h:outputLabel value="FullName:" for="fullName" />
                    <p:inputText id="fullName" value="#{userControl.newUser.fullName}" label="FullName" required="true">
                        <f:validateLength minimum="1"/>
                        <p:message id="msfn" for="fullName" display="FullName is not be empty"/>
                    </p:inputText>

                    <h:outputLabel value="Avatar:" for="avatar" />
                    <p:fileUpload id="avatar" mode="advanced" update="preview" sizeLimit="1000000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" auto="true"  fileUploadListener="#{userControl.handleFileUploadAddUser}" />  
                    <h:outputLabel value="Avatar:" for="preview" />
                    <h:commandLink id="preview" value="" ><img src="#{userControl.newUser.avatar}" height="100" width="70" /></h:commandLink>
                    
                    <h:outputLabel value="Birthday:" for="birthday" />  
                    <p:calendar id="dob" binding="#{userControl.dob}" mindate="01/01/1952" value="#{userControl.newUser.birthday}" navigator="true" required="true" requiredMessage="Choose your Birthday"/>


                    <h:outputLabel value="Phone" for="phone" />                                
                    <p:inputMask id="phone" value="#{userControl.newUser.phone}" mask="999-999-9999" validatorMessage="Phone is not valid" required="true">
                        <p:message for="phone"/>
                    </p:inputMask>

                    <h:outputLabel value="Address:" for="address" />
                    <p:inputText id="address" value="#{userControl.newUser.address}" title="Address" required="true">
                        <f:validateLength minimum="5"/>
                        <p:message id="msad" for="address" display="Address must be minium 5 char "/>
                    </p:inputText>

                    <h:outputLabel value="Email:" for="email" />
                    <p:inputText id="email" value="#{userControl.newUser.email}" required="true" label="Email" validatorMessage="#{userControl.newUser.email} is not valid">
                        <f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                        <p:message for="email" />
                    </p:inputText>

                    <h:outputLabel value="JoinedDate:" for="joinedDate" />
                    <p:calendar id="joinedDate" mindate="01/01/1970"  maxdate="17/05/2012" value="#{userControl.newUser.joinedDate}" navigator="true" required="true" requiredMessage="Choose your Joinedate"/>

                    <h:outputLabel value="IsAdmin:" for="isAdmin" />                                
                    <p:selectOneRadio id="isadmin" value="#{userControl.newUser.isAdmin}">  
                        <f:selectItem itemLabel="Yes" itemValue="true" />  
                        <f:selectItem itemLabel="No" itemValue="false" />    
                    </p:selectOneRadio>

                    <h:outputLabel value="IsActive:" for="isActive" />
                    <p:selectOneRadio id="isactive" value="#{userControl.newUser.isActive}">  
                        <f:selectItem itemLabel="Yes" itemValue="true" />  
                        <f:selectItem itemLabel="No" itemValue="false" />    
                    </p:selectOneRadio>

                    <h:outputLabel value="DepartmentName:" for="departmentName" />
                    <p:selectOneMenu value="#{userControl.newUser.departmentName}" required="true">
                        <f:selectItem itemLabel="Select One" itemValue=""/>
                        <f:selectItem itemLabel="Manager" itemValue="Manager"/>
                        <f:selectItem itemLabel="Maketing" itemValue="MaKeting"/>
                        <f:selectItem itemLabel="IT" itemValue="IT"/>
                        <f:selectItem itemLabel="Accounting" itemValue="Accounting"/>
                        <f:selectItem itemLabel="Sales" itemValue="Sales"/>
                        <f:selectItem itemLabel="Protection" itemValue="Protection"/>
                        <p:message for="departmentName" display="Please choose Department!!!"/>
                    </p:selectOneMenu>

                    <p:commandButton value="Insert" actionListener="#{userControl.insert()}" update="panel" icon="ui-icon-disk"/>
                    <p:commandButton value="reset" type="reset"/>
                </h:panelGrid>
            </p:panel>                                                                        
        </h:form>

    </ui:define>       
</ui:composition>


